package com.teamit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.teamit.entity.Employee;
import com.teamit.service.EmployeeService;
import com.teamit.util.web.ServletUtil;

public class LoginServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		ServletUtil.forword(request, response, "login");
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		EmployeeService es= new EmployeeService();
		
		String name = request.getParameter("name");
		String password = request.getParameter("password");
		
		//System.out.println(name);
		Employee employee = es.login(name,password);
		if(employee != null){
			ServletUtil.setSessionAttribute(request,"curr_employee",employee);
			ServletUtil.redirect(response, "/main.jspx");
			System.out.println("OK");
		}else{
			ServletUtil.redirect(response, "/index.jspx?state=10001");
		}
		
	}

}
